package com.lixin.smartclassroom.ui

import android.webkit.*
import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.api.agreement
import com.lixin.smartclassroom.api.pingtaicontent
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.base.databinding.ActivityWebUrlBinding
import com.lixinkeji.extension.getIntentInt
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.gone

/**
 *
 * @ClassName WebUrlActivity
 * @Author lwc
 * @Email 1679114787@qq.com
 * @Date 2022/4/6 17:34
 * @Des
 */
class WebHtmlActivity : BaseActivity<ActivityWebUrlBinding>() {
    override fun startPadding() = true
    override fun darkMode() = false
    override fun iniView() {
        val title = getIntentString("title")
        val url = getIntentString("url")
        val type = getIntentInt("type")
        if (title.isNotEmpty()) setTitle(title)


        scopeNetLife {
            when (type) {
                1 -> {
                    val baseBean = pingtaicontent()
                    if (baseBean.result == "0") {
                        binding.webView.loadDataWithBaseURL(
                            "about:blank",
                            baseBean.content!!,
                            "text/html",
                            "utf-8",
                            null
                        )
                    }

                }

                2,3 -> {
                    val baseBean = agreement(type.minus(1).toString())
                    if (baseBean.result == "0") {
                        binding.webView.loadDataWithBaseURL(
                            "about:blank",
                            baseBean.content!!,
                            "text/html",
                            "utf-8",
                            null
                        )
                    }
                }
                4->{
                    binding.webView.loadDataWithBaseURL(
                        "about:blank",
                        url,
                        "text/html",
                        "utf-8",
                        null
                    )
                }
            }
        }


    }

    override fun onResume() {
        super.onResume()
        binding.webView.onResume()
    }

    override fun onPause() {
        super.onPause()
        binding.webView.onPause()
    }

    override fun getViewBinding() = ActivityWebUrlBinding.inflate(layoutInflater)

}